import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Mohit Lokhande
 */
public class NS2 {
	public static void main(String []args) {
		
		
		@SuppressWarnings("resource")
		Scanner in = new Scanner(System.in);
		String input;
		
		//String key;
        int[] key;
        String lib = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        char[] stringtoarray = lib.toCharArray();
        
        
        System.out.println("ENTER THE STRING YOU WANT TO ENCRYPT:");
        
        input = in.nextLine();
        char[] cipher = input.toCharArray();
        
        
        
        System.out.println("\nENTER THE NUMBER OF KEYS:");
       // key = Integer.parseInt(in.nextLine());
        int size = Integer.parseInt(in.nextLine());
        key = new int [size];
        System.out.println("\nENTER KEYS:");
        for(int i=0;i<size;i++)
        {
            key[i] = Integer.parseInt(in.nextLine());

        }
     
        
        
        int keycount=0;
        //for encryption
        System.out.println("\nCIPHER TEXT IS:");
        
        
        for(int i = 0; i< cipher.length; i++)
        {
            for(int j = 0; j< stringtoarray.length; j++)
            {
                if (cipher[i] == stringtoarray[j])
                {
                    cipher[i] = stringtoarray[(j + key[keycount++%size]) % 52];
                    break;
                }
                
            }
            System.out.print(cipher[i]);
       
        }
       System.out.println("\n\nDECRYPTED TEXT IS:");
        
        int n=0 , l=0;
        keycount=0;
        
        for(int i = 0; i< cipher.length; i++)
        {
            for(int j = 0; j< stringtoarray.length; j++)
            {
                if (cipher[i] == stringtoarray[j])
                {
                    cipher[i] = stringtoarray[(j - key[keycount++%size]) % 52];
                    break;
                }
                
            }
            System.out.print(cipher[i]);
        
    
	}

	}
}	
